"""
---------------------------------------------------------------------
- File: logs.py
- Date: 2025/11/14
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 日志模块loguru 配置文件
---------------------------------------------------------------------
"""

from loguru import logger
import os

# 日志文件路径
os.makedirs("logs", exist_ok=True)

# 1. app日志
logger.add(
    "logs/app.log",
    rotation="200 MB",
    retention="30 days",
    encoding="utf-8",
    level="INFO",
    format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {name}:{function}:{line} | {message}",
)

# 2. 特殊glass日志
logger.add(
    "logs/glass.log",
    filter = lambda record: record["extra"].get("module") == "glass",
    rotation="200 MB",
    retention="30 days",
    encoding="utf-8",
    level="INFO"
)

# 3. 错误日志
logger.add(
    "logs/error.log",
    rotation="200 MB",
    retention="30 days",
    encoding="utf-8",
    level="ERROR",
    format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {name}:{function}:{line} - {message}"
)

# 4. 日志绑定,仅输出到指定日志文件， logger.info() 将输出到app.log中
glass_logger = logger.bind(module="glass")
error_logger = logger.bind(module="error")


